package com.itfenghuang.day14;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

//客户端,发送数据,基于TCP协议
public class A03_Client {
    public static void main(String[] args) throws IOException {
        /**
         *  客户端发送一个消息,服务端接受,并打印在控制台,然后回送给客户端消息
         */

         //创建Socket对象
        Socket socket = new Socket("127.0.0.1", 10086);
        //获取输出流
        OutputStream os = socket.getOutputStream();
        //获取输入流
        InputStream is = socket.getInputStream();
        os.write("咩啊".getBytes());
        //接受服务端的回送消息
        byte[] bys=new byte[1024];
        int read = is.read(bys);
        System.out.println(new String(bys,0,read));
        socket.close();

    }
}
